using Circus.CodeEditor;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
namespace Circus.CodeEditor.TextSource
{
	public class BookMarkManager
	{
		private class BookMarkList
		{
			private List<IBookMark> bookMarks = new List<IBookMark>();
			private SortList<IBookMark> sortedBookMarks = new SortList<IBookMark>();
			public int Count
			{
				get
				{
					return this.sortedBookMarks.Count;
				}
			}
			public IBookMark this[int index]
			{
				get
				{
					return this.sortedBookMarks[index];
				}
			}
			public void RemoveAt(int index)
			{
				IBookMark item = this.sortedBookMarks[index];
				this.sortedBookMarks.RemoveAt(index);
				this.bookMarks.Remove(item);
			}
			public bool FindFirst(IBookMark bookMark, out int index, IComparer<IBookMark> comparer)
			{
				return this.sortedBookMarks.FindFirst(bookMark, out index, comparer);
			}
			public bool FindFirst(object obj, out int index, IComparer comparer)
			{
				return this.sortedBookMarks.FindFirst(obj, out index, comparer);
			}
			public bool FindLast(IBookMark bookMark, out int index, IComparer<IBookMark> comparer)
			{
				return this.sortedBookMarks.FindLast(bookMark, out index, comparer);
			}
			public void Sort(IComparer<IBookMark> comparer)
			{
				this.sortedBookMarks.Sort(comparer);
			}
			public void Clear()
			{
				this.sortedBookMarks.Clear();
				this.bookMarks.Clear();
			}
			public void Insert(int index, IBookMark bookMark)
			{
				this.sortedBookMarks.Insert(index, bookMark);
				this.bookMarks.Add(bookMark);
			}
			public IBookMark Get(int index)
			{
				return this.bookMarks[index];
			}
		}
		private class LineComparer : IComparer<IBookMark>
		{
			public int Compare(IBookMark x, IBookMark y)
			{
				int num = x.Line - y.Line;
				if (num == 0)
				{
					num = string.Compare(x.FileName, y.FileName, true);
				}
				return num;
			}
		}
		private class BookMarkComparer : IComparer<IBookMark>
		{
			public int Compare(IBookMark x, IBookMark y)
			{
				int num = x.Line - y.Line;
				if (num == 0)
				{
					num = x.Group - y.Group;
				}
				if (num == 0)
				{
					num = x.Pos - y.Pos;
				}
				if (num == 0)
				{
					num = x.Index - y.Index;
				}
				return num;
			}
		}
		private class PointComparer : IComparer<IBookMark>
		{
			public int Compare(IBookMark x, IBookMark y)
			{
				int num = x.Line - y.Line;
				if (num == 0)
				{
					num = x.Group - y.Group;
				}
				if (num == 0)
				{
					num = x.Pos - y.Pos;
				}
				if (num == 0)
				{
					num = string.Compare(x.FileName, y.FileName, true);
				}
				return num;
			}
		}
		private class RangeComparer : IComparer
		{
			public int Compare(object x, object y)
			{
				IBookMark bookMark = (IBookMark)x;
				Point startPoint = ((Range)y).StartPoint;
				Point endPoint = ((Range)y).EndPoint;
				int result;
				if (bookMark.Line < startPoint.Y || (bookMark.Line == startPoint.Y && bookMark.Pos < startPoint.X))
				{
					result = -1;
				}
				else
				{
					if (bookMark.Line > endPoint.Y || (bookMark.Line == endPoint.Y && bookMark.Pos >= endPoint.X))
					{
						result = 1;
					}
					else
					{
						result = 0;
					}
				}
				return result;
			}
		}
		private BookMarkManager.BookMarkList bookMarks = new BookMarkManager.BookMarkList();
		private IComparer<IBookMark> lineComparer = new BookMarkManager.LineComparer();
		private IComparer<IBookMark> bookMarkComparer = new BookMarkManager.BookMarkComparer();
		private IComparer<IBookMark> pointComparer = new BookMarkManager.PointComparer();
		private IComparer rangeComparer = new BookMarkManager.RangeComparer();
		private IList<TextSource> sources = new List<TextSource>();
		private Hashtable images = new Hashtable();
		private Hashtable zIndex = new Hashtable();
		private Hashtable currentIndexes = new Hashtable();
		private int currentIndex = -1;
		private static BookMarkManager sharedBookMarks = null;
	    public event EventHandler<ActivateEventArgs> Activate;
	    public event EventHandler<BookMarkEventArgs> BookMarkAdded;

	    public event EventHandler<BookMarkEventArgs> BookMarkRemoved;
	    public event EventHandler<BookMarkChangedEventArgs> BookMarkPositionChanged;

	    public event EventHandler<BookMarkImageChangedEventArgs> BookMarkImageChanged;

	    public event EventHandler<BookmarkClickEventArgs> Click;
	    public event EventHandler<BookmarkClickEventArgs> DoubleClick;
	    public event EventHandler<BookMarkToolTipEventArgs> ShowToolTip;
		public static BookMarkManager SharedBookMarks
		{
			get
			{
				if (BookMarkManager.sharedBookMarks == null)
				{
					BookMarkManager.sharedBookMarks = new BookMarkManager();
				}
				return BookMarkManager.sharedBookMarks;
			}
		}
		protected TextSource FindSource(string fileName, bool activate)
		{
			TextSource result = null;
			foreach (TextSource current in this.sources)
			{
				if (string.Compare(current.FileName, fileName, true) == 0)
				{
					result = current;
					break;
				}
			}
			if (activate)
			{
				this.OnActivate(fileName, ref result);
			}
			return result;
		}
		protected bool ShouldDelete(IBookMark bm, Rectangle rect)
		{
			bool result;
			if (bm.Index == int.MaxValue)
			{
				result = (SortList<IBookMark>.InsideRange(new Point(0, bm.Line), rect) && (rect.Width == int.MaxValue || SortList<IBookMark>.InsideRange(new Point(int.MaxValue, bm.Line), rect)));
			}
			else
			{
				result = SortList<IBookMark>.InsideRange(new Point(bm.Pos, bm.Line), rect);
			}
			return result;
		}
		protected bool UpdatePosition(int x, int y, int deltaX, int deltaY, IBookMark bookMark)
		{
			Point point = new Point(bookMark.Pos, bookMark.Line);
			bool result;
			if (SortList<IBookMark>.UpdatePos(x, y, deltaX, deltaY, ref point, point.X != 0))
			{
				bookMark.Position = new Point((bookMark.Index != int.MaxValue) ? point.X : bookMark.Pos, point.Y);
				result = true;
			}
			else
			{
				result = false;
			}
			return result;
		}
		protected void UpdateCurrentIndexes()
		{
			IList<int> list = new List<int>();
			foreach (int num in this.currentIndexes.Keys)
			{
				list.Add(num);
			}
			foreach (int num in list)
			{
				int num2 = (int)this.currentIndexes[num];
				if (num2 >= this.bookMarks.Count)
				{
					this.currentIndexes[num] = this.bookMarks.Count - 1;
				}
			}
			this.currentIndex = Math.Min(this.currentIndex, this.bookMarks.Count - 1);
		}
		protected void ClearBookMarkByIndex(int index, string fileName)
		{
			if (index >= 0 && index < this.bookMarks.Count)
			{
				IBookMark bookMark = this.bookMarks[index];
				TextSource textSource = this.FindSource(fileName, false);
				if (textSource != null)
				{
					textSource.BeginUpdate(UpdateReason.Other);
					try
					{
						int line = this.bookMarks[index].Line;
						this.bookMarks.RemoveAt(index);
						this.OnBookMarkRemoved(bookMark);
						textSource.State |= NotifyState.BookMarkChanged;
						textSource.LinesChanged(line, line);
					}
					finally
					{
						textSource.EndUpdate();
					}
				}
				else
				{
					this.bookMarks.RemoveAt(index);
					this.OnBookMarkRemoved(this.bookMarks[index]);
				}
				this.UpdateCurrentIndexes();
			}
		}
		protected void InternalSet(Point position, int group, int bookMark, int imageIndex, string name, string description, string url, object tag, string fileName)
		{
			int index;
			if (this.bookMarks.FindFirst(new BookMark(position.Y, position.X, bookMark, group, imageIndex, fileName), out index, this.pointComparer))
			{
				this.bookMarks.RemoveAt(index);
				this.OnBookMarkRemoved(this.bookMarks[index]);
			}
			IBookMark bookMark2 = new BookMark(position.Y, position.X, group, bookMark, imageIndex, name, description, url, fileName, tag);
			this.bookMarks.Insert(index, bookMark2);
			this.OnBookMarkAdded(bookMark2);
			if (group != -1)
			{
				this.currentIndexes[group] = this.bookMarks.Count - 1;
			}
			this.currentIndex = this.bookMarks.Count - 1;
		}
		protected int GetNextBookMarkIndex(int group, bool direction)
		{
			int i;
			if (group == -1)
			{
				i = this.currentIndex;
			}
			else
			{
				object obj = this.currentIndexes[group];
				i = ((obj != null) ? ((int)obj) : -1);
			}
			int result;
			if (direction)
			{
				for (i++; i < this.bookMarks.Count; i++)
				{
					IBookMark bookMark = this.bookMarks.Get(i);
					if (group == -1 || bookMark.Group == group)
					{
						break;
					}
				}
				if (i >= this.bookMarks.Count)
				{
					i = 0;
				}
				while (i < this.bookMarks.Count)
				{
					IBookMark bookMark = this.bookMarks.Get(i);
					if (group == -1 || bookMark.Group == group)
					{
						result = i;
						return result;
					}
					i++;
				}
			}
			else
			{
				for (i--; i > 0; i--)
				{
					IBookMark bookMark = this.bookMarks.Get(i);
					if (group == -1 || bookMark.Group == group)
					{
						break;
					}
				}
				if (i < 0)
				{
					i = this.bookMarks.Count - 1;
				}
				while (i > 0)
				{
					IBookMark bookMark = this.bookMarks.Get(i);
					if (group == -1 || bookMark.Group == group)
					{
						result = i;
						return result;
					}
					i--;
				}
			}
			result = -1;
			return result;
		}
		protected bool GotoBookMarkIndex(int group, bool direction)
		{
			int nextBookMarkIndex = this.GetNextBookMarkIndex(group, direction);
			bool result;
			if (nextBookMarkIndex >= 0 && nextBookMarkIndex < this.bookMarks.Count)
			{
				if (group != -1)
				{
					this.currentIndexes[group] = nextBookMarkIndex;
				}
				this.currentIndex = nextBookMarkIndex;
				IBookMark bookMark = this.bookMarks.Get(nextBookMarkIndex);
				TextSource textSource = this.FindSource(bookMark.FileName, true);
				if (textSource != null)
				{
					textSource.BeginUpdate(UpdateReason.Navigate);
					try
					{
						textSource.State |= (NotifyState.GotoBookMark | NotifyState.CenterLine);
						textSource.MoveTo(bookMark.Pos, bookMark.Line);
					}
					finally
					{
						textSource.EndUpdate();
					}
				}
				result = true;
			}
			else
			{
				result = false;
			}
			return result;
		}
		protected int FindByLine(int line, string fileName)
		{
			int num;
			int result;
			if (this.bookMarks.FindFirst(new BookMark(line, fileName), out num, this.lineComparer))
			{
				result = num;
			}
			else
			{
				result = -1;
			}
			return result;
		}
		protected int InternalFindBookMark(int line, int group, int bookMark, string fileName)
		{
			int num = this.FindByLine(line, fileName);
			while (num >= 0 && num < this.bookMarks.Count)
			{
				IBookMark bookMark2 = this.bookMarks[num];
				if (bookMark2.Line != line || string.Compare(bookMark2.FileName, fileName, true) != 0)
				{
					num = -1;
					break;
				}
				if ((bookMark2.Group == group || group == -1) && bookMark2.Index == bookMark)
				{
					break;
				}
				num++;
			}
			int result;
			if (num >= 0 && num < this.bookMarks.Count && this.bookMarks[num].Line == line)
			{
				result = num;
			}
			else
			{
				result = -1;
			}
			return result;
		}
		protected int InternalFindBookMark(int line, int group, string fileName)
		{
			int num = this.FindByLine(line, fileName);
			while (num >= 0 && num < this.bookMarks.Count)
			{
				IBookMark bookMark = this.bookMarks[num];
				if (bookMark.Line != line || string.Compare(bookMark.FileName, fileName, true) != 0)
				{
					num = -1;
					break;
				}
				if (bookMark.Group == group || group == -1)
				{
					break;
				}
				num++;
			}
			int result;
			if (num >= 0 && num < this.bookMarks.Count && this.bookMarks[num].Line == line)
			{
				result = num;
			}
			else
			{
				result = -1;
			}
			return result;
		}
		public void ClearBookMark(int line, int group, int bookMark, string fileName)
		{
			int num = 0;
			if (this.bookMarks.FindLast(new BookMark(line, fileName), out num, this.lineComparer))
			{
				for (int i = num; i >= 0; i--)
				{
					IBookMark bookMark2 = this.bookMarks[i];
					if (bookMark2.Line != line || (bookMark2.Group != group && group != -1) || string.Compare(bookMark2.FileName, fileName, true) != 0)
					{
						break;
					}
					if (bookMark2.Index == bookMark)
					{
						this.ClearBookMarkByIndex(num, fileName);
					}
				}
			}
		}
		public void ClearBookMarks(int line, int group, string fileName)
		{
			int num = 0;
			bool flag = false;
			if (this.bookMarks.FindLast(new BookMark(line, fileName), out num, this.lineComparer))
			{
				for (int i = num; i >= 0; i--)
				{
					IBookMark bookMark = this.bookMarks[i];
					if (bookMark.Line != line || string.Compare(bookMark.FileName, fileName, true) != 0)
					{
						break;
					}
					if (bookMark.Group == group || group == -1)
					{
						this.bookMarks.RemoveAt(i);
						this.OnBookMarkRemoved(bookMark);
						flag = true;
					}
				}
			}
			if (flag)
			{
				TextSource textSource = this.FindSource(fileName, false);
				if (textSource != null)
				{
					textSource.BeginUpdate(UpdateReason.Other);
					try
					{
						textSource.LinesChanged(line, line);
						textSource.State |= NotifyState.BookMarkChanged;
					}
					finally
					{
						textSource.EndUpdate();
					}
				}
			}
			this.UpdateCurrentIndexes();
		}
		public IBookMark GetCurrentBookMark(int group)
		{
			int num;
			if (group == -1)
			{
				num = this.currentIndex;
			}
			else
			{
				object obj = this.currentIndexes[group];
				num = ((obj != null) ? ((int)obj) : -1);
			}
			return (num >= 0 && num < this.bookMarks.Count) ? this.bookMarks.Get(num) : null;
		}
		public int GetBookMarkCount(int group, string fileName)
		{
			int num = 0;
			for (int i = 0; i < this.bookMarks.Count; i++)
			{
				IBookMark bookMark = this.bookMarks.Get(i);
				if (group == -1 || bookMark.Group == group || (fileName == null || fileName == string.Empty) || bookMark.FileName == fileName)
				{
					num++;
				}
			}
			return num;
		}
		public bool BlockDeleting(Rectangle rect, string fileName)
		{
			bool result;
			if (fileName == null || fileName == string.Empty)
			{
				result = false;
			}
			else
			{
				bool flag = false;
				int num;
				this.bookMarks.FindLast(new BookMark(rect.Bottom, fileName), out num, this.lineComparer);
				if (num >= 0)
				{
					for (int i = Math.Min(num, this.bookMarks.Count - 1); i >= 0; i--)
					{
						IBookMark bookMark = this.bookMarks[i];
						if (bookMark.Line < rect.Top)
						{
							break;
						}
						if (string.Compare(bookMark.FileName, fileName, true) == 0)
						{
							if (this.ShouldDelete(bookMark, rect))
							{
								flag = true;
								this.bookMarks.RemoveAt(i);
								this.OnBookMarkRemoved(bookMark);
							}
						}
					}
				}
				this.UpdateCurrentIndexes();
				result = flag;
			}
			return result;
		}
		public void Clear(int group, string fileName)
		{
			bool flag = false;
			for (int i = this.bookMarks.Count - 1; i >= 0; i--)
			{
				IBookMark bookMark = this.bookMarks[i];
				if ((bookMark.Group == group || group == -1) && string.Compare(bookMark.FileName, fileName, true) == 0)
				{
					this.bookMarks.RemoveAt(i);
					this.OnBookMarkRemoved(bookMark);
					flag = true;
				}
			}
			if (flag)
			{
				TextSource textSource = this.FindSource(fileName, false);
				if (textSource != null)
				{
					textSource.BeginUpdate(UpdateReason.Other);
					try
					{
						textSource.LinesChanged(0, int.MaxValue);
						textSource.State |= NotifyState.BookMarkChanged;
					}
					finally
					{
						textSource.EndUpdate();
					}
				}
			}
			this.UpdateCurrentIndexes();
		}
		public void Clear(string fileName)
		{
			this.Clear(-1, fileName);
		}
		public void Clear()
		{
			this.bookMarks.Clear();
			this.currentIndexes.Clear();
			this.currentIndex = -1;
		}
		public void ClearUnnumberedBookMarks(string fileName)
		{
			bool flag = false;
			for (int i = this.bookMarks.Count - 1; i >= 0; i--)
			{
				IBookMark bookMark = this.bookMarks[i];
				if (bookMark.Index == int.MaxValue && string.Compare(bookMark.FileName, fileName, true) == 0)
				{
					this.bookMarks.RemoveAt(i);
					this.OnBookMarkRemoved(bookMark);
					flag = true;
				}
			}
			if (flag)
			{
				TextSource textSource = this.FindSource(fileName, false);
				if (textSource != null)
				{
					textSource.BeginUpdate(UpdateReason.Other);
					try
					{
						textSource.LinesChanged(0, int.MaxValue);
						textSource.State |= NotifyState.BookMarkChanged;
					}
					finally
					{
						textSource.EndUpdate();
					}
				}
			}
			this.UpdateCurrentIndexes();
		}
		public bool PositionChanged(int x, int y, int deltaX, int deltaY, string fileName)
		{
			int num = 0;
			this.bookMarks.FindFirst(new BookMark(y, fileName), out num, this.lineComparer);
			bool result;
			if (num >= 0)
			{
				bool flag = false;
				for (int i = num; i < this.bookMarks.Count; i++)
				{
					IBookMark bookMark = this.bookMarks[i];
					if (string.Compare(bookMark.FileName, fileName, true) == 0)
					{
						Point position = bookMark.Position;
						if (this.UpdatePosition(x, y, deltaX, deltaY, bookMark))
						{
							this.OnBookMarkPositionChanged(bookMark, position);
							flag = true;
						}
					}
				}
				if (flag)
				{
					this.bookMarks.Sort(this.bookMarkComparer);
					result = true;
					return result;
				}
			}
			result = false;
			return result;
		}
		public void SetBookMark(Point position, int group, int bookMark, int imageIndex, string name, string description, string url, object tag, string fileName)
		{
			TextSource textSource = this.FindSource(fileName, false);
			if (textSource != null)
			{
				textSource.BeginUpdate(UpdateReason.Other);
				try
				{
					this.InternalSet(position, group, bookMark, imageIndex, name, description, url, tag, fileName);
					textSource.LinesChanged(position.Y, position.Y);
					textSource.State |= NotifyState.BookMarkChanged;
				}
				finally
				{
					textSource.EndUpdate();
				}
			}
			else
			{
				this.InternalSet(position, group, bookMark, imageIndex, name, description, url, tag, fileName);
			}
		}
		public bool GotoNextBookMark()
		{
			return this.GotoBookMarkIndex(-1, true);
		}
		public bool GotoPrevBookMark()
		{
			return this.GotoBookMarkIndex(-1, false);
		}
		public bool GotoNextBookMark(int group)
		{
			return this.GotoBookMarkIndex(group, true);
		}
		public bool GotoPrevBookMark(int group)
		{
			return this.GotoBookMarkIndex(group, false);
		}
		public bool CanMoveToNextBookMark(int group)
		{
			return this.GetNextBookMarkIndex(group, true) >= 0;
		}
		public bool CanMoveToPreviousBookMark(int group)
		{
			return this.GetNextBookMarkIndex(group, false) >= 0;
		}
		public virtual int NextBookMark(int group, string fileName)
		{
			int num = -1;
			for (int i = 0; i < this.bookMarks.Count; i++)
			{
				IBookMark bookMark = this.bookMarks[i];
				if ((bookMark.Group == group || group == -1) && string.Compare(bookMark.FileName, fileName, true) == 0)
				{
					num = Math.Max(bookMark.Index, num);
				}
			}
			return num + 1;
		}
		public IBookMark FindBookMark(int line, int group, int bookMark, string fileName)
		{
			int num = this.InternalFindBookMark(line, group, bookMark, fileName);
			return (num >= 0) ? this.bookMarks[num] : null;
		}
		public IBookMark FindBookMark(int bookMark, string fileName)
		{
			IBookMark result;
			for (int i = 0; i < this.bookMarks.Count; i++)
			{
				IBookMark bookMark2 = this.bookMarks[i];
				if (bookMark2.Index == bookMark && string.Compare(bookMark2.FileName, fileName, true) == 0)
				{
					result = bookMark2;
					return result;
				}
			}
			result = null;
			return result;
		}
		public IBookMark FindBookMark(int line, int group, string fileName)
		{
			int num = this.InternalFindBookMark(line, group, fileName);
			return (num >= 0) ? this.bookMarks[num] : null;
		}
		public IBookMark FindBookMark(string name, string fileName)
		{
			IBookMark result;
			for (int i = 0; i < this.bookMarks.Count; i++)
			{
				IBookMark bookMark = this.bookMarks[i];
				if (bookMark.Name == name && string.Compare(bookMark.FileName, fileName, true) == 0)
				{
					result = bookMark;
					return result;
				}
			}
			result = null;
			return result;
		}
		public void ToggleBookMark(Point position, int group, int bookMark, int imageIndex, string name, string description, string url, object tag, string fileName)
		{
			int num = this.InternalFindBookMark(position.Y, group, bookMark, fileName);
			if (num >= 0)
			{
				this.ClearBookMarkByIndex(num, fileName);
			}
			else
			{
				this.SetBookMark(position, group, bookMark, imageIndex, name, description, url, tag, fileName);
			}
		}
		public int GetBookMark(int line, int group, string fileName)
		{
			int num;
			int result;
			if (this.bookMarks.FindFirst(new BookMark(line, fileName), out num, this.lineComparer))
			{
				for (int i = num; i < this.bookMarks.Count; i++)
				{
					IBookMark bookMark = this.bookMarks[i];
					if (bookMark.Line != line || string.Compare(bookMark.FileName, fileName, true) != 0)
					{
						break;
					}
					if (bookMark.Group == group || group == -1)
					{
						result = bookMark.Index;
						return result;
					}
				}
			}
			result = -1;
			return result;
		}
		public int GetBookMarks(Point startPoint, Point endPoint, int group, string fileName, IList<IBookMark> list)
		{
			list.Clear();
			Range range = new Range(startPoint, endPoint);
			int num;
			if (this.bookMarks.FindFirst(range, out num, this.rangeComparer))
			{
				for (int i = num; i < this.bookMarks.Count; i++)
				{
					IBookMark bookMark = this.bookMarks[i];
					if (this.rangeComparer.Compare(bookMark, range) != 0)
					{
						break;
					}
					if ((bookMark.Group == group || group == -1) && string.Compare(bookMark.FileName, fileName, true) == 0)
					{
						list.Add(bookMark);
					}
				}
			}
			return list.Count;
		}
		public int GetBookMarks(int group, string fileName, IList<IBookMark> list)
		{
			list.Clear();
			for (int i = 0; i < this.bookMarks.Count; i++)
			{
				IBookMark bookMark = this.bookMarks[i];
				if ((bookMark.Group == group || group == -1) && string.Compare(bookMark.FileName, fileName, true) == 0)
				{
					list.Add(bookMark);
				}
			}
			return list.Count;
		}
		public int GetBookMark(Point startPoint, Point endPoint, int group, string fileName)
		{
			Range range = new Range(startPoint, endPoint);
			int num;
			int result;
			if (this.bookMarks.FindFirst(range, out num, this.rangeComparer))
			{
				for (int i = num; i < this.bookMarks.Count; i++)
				{
					IBookMark bookMark = this.bookMarks[i];
					if (this.rangeComparer.Compare(bookMark, range) != 0)
					{
						break;
					}
					if ((bookMark.Group == group || group == -1) && string.Compare(bookMark.FileName, fileName, true) == 0)
					{
						result = bookMark.Index;
						return result;
					}
				}
			}
			result = -1;
			return result;
		}
		public int GetZIndex(int group)
		{
			object obj = this.zIndex[group];
			return (obj != null) ? ((int)obj) : 0;
		}
		public void SetZIndex(int group, int value)
		{
			this.zIndex[group] = value;
		}
		public void OnActivate(string fileName, ref TextSource source)
		{
			if (this.Activate != null)
			{
				ActivateEventArgs activateEventArgs = new ActivateEventArgs(fileName, source);
				this.Activate(this, activateEventArgs);
				source = activateEventArgs.Source;
			}
		}
		public void OnBookMarkAdded(IBookMark bookMark)
		{
			if (this.BookMarkAdded != null)
			{
				this.BookMarkAdded(this, new BookMarkEventArgs(bookMark));
			}
		}
		public void OnBookMarkRemoved(IBookMark bookMark)
		{
			if (this.BookMarkRemoved != null)
			{
				this.BookMarkRemoved(this, new BookMarkEventArgs(bookMark));
			}
		}
		public void OnBookMarkPositionChanged(IBookMark bookMark, Point position)
		{
			if (this.BookMarkPositionChanged != null)
			{
				this.BookMarkPositionChanged(this, new BookMarkChangedEventArgs(bookMark, position));
			}
		}
		public void OnBookMarkImageChanged(IBookMark bookMark, int imageIndex)
		{
			if (this.BookMarkImageChanged != null)
			{
				this.BookMarkImageChanged(this, new BookMarkImageChangedEventArgs(bookMark, imageIndex));
			}
		}
		public virtual void OnClick(IBookMark bookMark)
		{
			if (this.Click != null)
			{
				this.Click(this, new BookmarkClickEventArgs(bookMark));
			}
		}
		public virtual void OnDoubleClick(IBookMark bookMark)
		{
			if (this.DoubleClick != null)
			{
				this.DoubleClick(this, new BookmarkClickEventArgs(bookMark));
			}
		}
		public virtual bool OnShowTooltip(ref string tooltip, IBookMark bookMark)
		{
			bool result;
			if (this.ShowToolTip != null)
			{
				BookMarkToolTipEventArgs bookMarkToolTipEventArgs = new BookMarkToolTipEventArgs(tooltip, bookMark);
				this.ShowToolTip(this, bookMarkToolTipEventArgs);
				tooltip = bookMarkToolTipEventArgs.Tooltip;
				result = bookMarkToolTipEventArgs.Handled;
			}
			else
			{
				result = false;
			}
			return result;
		}
		public ImageList GetImages(int group)
		{
			return this.images[group] as ImageList;
		}
		public static void Register(TextSource source)
		{
			BookMarkManager.SharedBookMarks.sources.Add(source);
		}
		public static void Unregister(TextSource source)
		{
			BookMarkManager.SharedBookMarks.sources.Remove(source);
		}
		public static void RegisterImages(ImageList imageList, int group)
		{
			BookMarkManager.SharedBookMarks.images[group] = imageList;
		}
	}
}
